#ifndef __ST7789_H_
#define __ST7789_H_

#include "headfile.h"

//---------------------------------------------------------------------------------------------------------------
#define SPI_INST (SPI_0_INST)                   // SPI通道
#define GPIO_PORT (GPIO_GRP_LCD_PORT)           // GPIO_PORT
#define GPIO_RES_PIN (GPIO_GRP_LCD_PIN_RST_PIN) // RES
#define GPIO_DC_PIN (GPIO_GRP_LCD_PIN_DC_PIN)   // DC
#define GPIO_CS_PIN (GPIO_GRP_LCD_PIN_CS_PIN)   // CS
//---------------------------------------------------------------------------------------------------------------

#define IPS154_DEFAULT_DISPLAY_DIR (IPS154_PORTAIT)    // 默认的显示方向
#define IPS154_DEFAULT_PENCOLOR (RGB565_RED)           // 默认的画笔颜色
#define IPS154_DEFAULT_BGCOLOR (RGB565_WHITE)          // 默认的背景颜色
#define IPS154_DEFAULT_DISPLAY_FONT (IPS154_8X16_FONT) // 默认的字体模式
#define LCD_W 240                                      // 屏幕尺寸W
#define LCD_H 240                                      // 屏幕尺寸H

#define IPS154_RES(x)                                                          \
  ((x) ? DL_GPIO_setPins(GPIO_PORT, GPIO_RES_PIN)                              \
       : DL_GPIO_clearPins(GPIO_PORT, GPIO_RES_PIN))
#define IPS154_DC(x)                                                           \
  ((x) ? DL_GPIO_setPins(GPIO_PORT, GPIO_DC_PIN)                               \
       : DL_GPIO_clearPins(GPIO_PORT, GPIO_DC_PIN))
#define IPS154_CS(x)                                                           \
  ((x) ? DL_GPIO_setPins(GPIO_PORT, GPIO_CS_PIN)                               \
       : DL_GPIO_clearPins(GPIO_PORT, GPIO_CS_PIN))

//---------------------------------------------------------------------------------------------------------------
typedef enum {
  IPS154_PORTAIT = 0,       // 竖屏模式
  IPS154_PORTAIT_180 = 1,   // 竖屏模式  旋转180
  IPS154_CROSSWISE = 2,     // 横屏模式
  IPS154_CROSSWISE_180 = 3, // 横屏模式  旋转180
} ips154_dir_enum;

typedef enum {
  IPS154_6X8_FONT = 0,   // 6x8      字体
  IPS154_8X16_FONT = 1,  // 8x16     字体
  IPS154_16X16_FONT = 2, // 16x16    字体 目前不支持
} ips154_font_size_enum;
//---------------------------------------------------------------------------------------------------------------

void ips154_init(void);

void ips154_clear(void);
void ips154_full(const uint16_t color);
void ips154_set_color(uint16_t pen, const uint16_t bgcolor);
void ips154_draw_point(uint16_t x, uint16_t y, const uint16_t color);
void ips154_draw_line(uint16_t x_start, uint16_t y_start, uint16_t x_end,
                      uint16_t y_end, const uint16_t color);
void ips154_draw_rectangle(uint16_t x_start, uint16_t y_start, uint16_t width,
                           uint16_t height, uint8_t filled,
                           const uint16_t color);
void ips154_draw_circle(uint16_t x_center, uint16_t y_center, uint16_t radius,
                        uint8_t filled, const uint16_t color);
void ips154_show_char(uint16_t x, uint16_t y, const char dat);
void ips154_show_string(uint16_t x, uint16_t y, const char dat[]);
void ips154_show_int(uint16_t x, uint16_t y, const int32_t dat, uint8_t num);
void ips154_show_uint(uint16_t x, uint16_t y, const uint32_t dat, uint8_t num);
void ips154_show_float(uint16_t x, uint16_t y, const double dat, uint8_t num,
                       uint8_t pointnum);
void ips154_draw_image(uint16_t x_start, uint16_t y_start, uint16_t x_end,
                       uint16_t y_end, const uint8_t *imgBuf);
#endif
